package com.weixin.paleituo.factory;

import android.os.Bundle;
import android.support.v4.app.Fragment;

import com.weixin.paleituo.bean.BuyHouseStepBean;
import com.weixin.paleituo.contans.Contans;
import com.weixin.paleituo.fragment.AcceptHouseFragment;
import com.weixin.paleituo.fragment.IntakeHouseFragment;
import com.weixin.paleituo.fragment.PredetermineHouseFragment;
import com.weixin.paleituo.fragment.SignedHouseFragment;
import com.weixin.paleituo.util.LogUtils;

import java.util.HashMap;

/**
 * Author yichao
 * Time  2017/11/30 9:36
 * Dest  售房进度fragment的工厂
 */

public class SaleHouseStepFragmentFactory {
    public static String TAG="SaleHouseStepFragmentFactory";
    private static final int PREDETERMINEHOUSE_FRAGMENT = 0;
    private static final int SIGNEDHOUSE_FRAGMENT = 1;
    private static final int ACCEPTHOUSE_FRAGMENT = 2;
    private static final int INTAKEHOUSE_FRAGMENT = 3;
    private static HashMap<Integer,Fragment> mMap=new HashMap();
    private static Bundle sBundle;


    public static Fragment getFragment(int index, BuyHouseStepBean buyHouseStepBean) {
        Fragment fragment=null;
        if (mMap.containsKey(index)){
            fragment=   mMap.get(index);
            LogUtils.i(TAG,"复用"+index);

            sBundle = new Bundle();
            switch (index){
                case PREDETERMINEHOUSE_FRAGMENT:
                    sBundle.clear();
                    sBundle.putParcelable(Contans.INTENT_DATA,buyHouseStepBean.getPurchase());
                    fragment.setArguments(sBundle);
                    break;
                case SIGNEDHOUSE_FRAGMENT:
                    sBundle.clear();
                    sBundle.putParcelable(Contans.INTENT_DATA,buyHouseStepBean.getSign());
                    fragment.setArguments(sBundle);
                    break;
                case ACCEPTHOUSE_FRAGMENT:
                    sBundle.clear();
                    sBundle.putParcelable(Contans.INTENT_DATA,buyHouseStepBean.getTake());
                    fragment.setArguments(sBundle);
                    break;
                case INTAKEHOUSE_FRAGMENT:
                    sBundle.clear();
                    sBundle.putParcelable(Contans.INTENT_DATA,buyHouseStepBean.getCheck());
                    fragment.setArguments(sBundle);
                    break;
            }

        }else {
            switch (index) {
                case PREDETERMINEHOUSE_FRAGMENT:
                    fragment =  PredetermineHouseFragment.newInstance(buyHouseStepBean.getPurchase());
                    break;
                case SIGNEDHOUSE_FRAGMENT:
                    fragment =  SignedHouseFragment.newInstance(buyHouseStepBean.getSign());
                    break;
                case ACCEPTHOUSE_FRAGMENT:
                    fragment =  AcceptHouseFragment.newInstance(buyHouseStepBean.getTake());
                    break;
                case INTAKEHOUSE_FRAGMENT:
                    fragment =  IntakeHouseFragment.newInstance(buyHouseStepBean.getCheck());
                    break;
            }
            LogUtils.i(TAG,"新建"+index);
            mMap.put(index,fragment);

        }

        return fragment;

    }
    /**fragment的个数*/
public static int size(){
        return 4;
}

}
